package io.renren.modules.biz.service.impl;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.biz.dao.TeamDao;
import io.renren.modules.biz.entity.CountDto;
import io.renren.modules.biz.entity.MemberEntity;
import io.renren.modules.biz.entity.TeamEntity;
import io.renren.modules.biz.entity.TeamTreeDto;
import io.renren.modules.biz.service.TeamService;

import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

@Service("teamService")
public class TeamServiceImpl extends ServiceImpl<TeamDao, TeamEntity> implements TeamService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		Page<TeamEntity> page = this.selectPage(new Query<TeamEntity>(params).getPage(), new EntityWrapper<TeamEntity>());

		return new PageUtils(page);
	}

	@Override
	public PageUtils selectMemberTeam(Map<String, Object> params) {
		Long id = Long.valueOf(params.get("id").toString());
		Integer level = Integer.valueOf(params.get("level").toString());
		Page<MemberEntity> page = new Query<MemberEntity>(params).getPage();
		page = page.setRecords(baseMapper.selectMemberTeam(page, level, id));
		return new PageUtils(page);
	}

	@Override
	public CountDto countTeam(Long memberId, String startDate, String endDate) {
		return baseMapper.countTeam(memberId, startDate, endDate);
	}

	@Override
	public TeamTreeDto selectAccountingByMemberId(Long memberId, String startDate, String endDate) {
		return baseMapper.selectAccountingByMemberId(memberId, startDate, endDate);
	}

	@Override
	public PageUtils selectAccountingByHigher(Page<TeamTreeDto> page, Integer level, Long memberId, String startDate, String endDate) {
		page = page.setRecords(baseMapper.selectAccountingByHigher(page, level, memberId, startDate, endDate));
		return new PageUtils(page);
	}
}
